package cn.tedu.datamanager.controller;


import cn.tedu.datamanager.pojo.dto.ServicesAddNewDTO;
import cn.tedu.datamanager.pojo.vo.ServicesListItemVO;
import cn.tedu.datamanager.serve.IServicesService;
import cn.tedu.datamanager.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "02. 服务项目模块")
@RestController
@RequestMapping("/services")
public class ServicesController {
    @Autowired
    IServicesService Service;

    // http://localhost:9081/service
    @ApiOperation("查询服务项目列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<ServicesListItemVO>> list() {
        log.debug("开始处理【查询服务项目列表】的请求");
        List<ServicesListItemVO> list = Service.list();
        return JsonResult.ok(list);
    }

    // http://localhost:8080/service/add-new?xxxx
    @ApiOperation("添加服务项目")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated ServicesAddNewDTO servicesAddNewDTO) {
        log.debug("开始处理【添加服务项目】的请求，参数：{}", servicesAddNewDTO);
        Service.addNew(servicesAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:8080/service/9527/delete
    @ApiOperation("删除服务项目")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "Id", value = "服务项目id", required = true, dataType = "long")
    @PostMapping("/{Id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long Id) {
        log.debug("开始处理【删除服务项目】的请求，参数：{}", Id);
        Service.delete(Id);
        return JsonResult.ok();
    }

    // http://localhost:9081/service/xx/enable
    @ApiOperation("启用服务项目")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "Id", value = "项目serviceId", required = true, dataType = "long")
    @PostMapping("/{Id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long Id) {
        log.debug("开始处理【启用服务项目】的请求，参数：{}", Id);
        Service.setEnable(Id);
        return JsonResult.ok();
    }

    // http://localhost:9081/service/xx/disable
    @ApiOperation("停用服务项目")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "Id", value = "服务项目id", required = true, dataType = "long")
    @PostMapping("/{Id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long Id) {
        log.debug("开始处理【停用服务项目】的请求，参数：{}", Id);
        Service.setDisable(Id);
        return JsonResult.ok();
    }

    // http://localhost:9081/service
    @ApiOperation("修改前查询")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParam(name = "Id", value = "服务项目id", required = true, dataType = "long")
    @PostMapping("/selectupdate/{Id:[0-9]+}")
    public JsonResult selectupdate(@PathVariable Long Id) {
        log.debug("开始处理【查询服务项目列表】的请求");
        return JsonResult.ok(Service.selectupdate(Id));
    }

    // http://localhost:9081/services/update/2
    @ApiOperation("修改服务项目")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParam(name = "Id", value = "服务项目id", required = true, dataType = "long")
    @PostMapping("/{Id:[0-9]+}/update")
    public JsonResult update(@PathVariable Long Id,@Validated ServicesAddNewDTO servicesAddNewDTO) {
        log.debug("开始处理【修改服务项目】的请求，参数：{}", servicesAddNewDTO);
        log.debug("开始处理【修改服务项目】的请求，id：{}", Id);
        Service.update(servicesAddNewDTO);
        return JsonResult.ok();
    }
}
